/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Universidad de Almeria
 * License Type: Purchased
 */
package orm;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class RegistroDAO {
	public static Registro loadRegistroByORMID(String telefono) throws PersistentException  {
		PersistentSession session = orm.AgendaRMI2PersistentManager.instance().getSession();
		return loadRegistroByORMID(session, telefono);
	}
	
	public static Registro loadRegistroByORMID(PersistentSession session, String telefono) throws PersistentException {
		return (Registro) session.load(orm.Registro.class, telefono);
	}
	
	public static Registro[] listRegistroByQuery(String condition, String orderBy) throws PersistentException  {
		PersistentSession session = orm.AgendaRMI2PersistentManager.instance().getSession();
		return listRegistroByQuery(session, condition, orderBy);
	}
	
	public static Registro[] listRegistroByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Registro as Registro");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		Query query = session.createQuery(sb.toString());
		try {
			List list = query.list();
			return (Registro[]) list.toArray(new Registro[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Registro loadRegistroByQuery(String condition, String orderBy) throws PersistentException {
		PersistentSession session = orm.AgendaRMI2PersistentManager.instance().getSession();
		return loadRegistroByQuery(session, condition, orderBy);
	}
	
	public static Registro loadRegistroByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Registro[] registros = listRegistroByQuery(session, condition, orderBy);
		if (registros != null && registros.length > 0)
			return registros[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateRegistroByQuery(String condition, String orderBy) throws PersistentException  {
		PersistentSession session = orm.AgendaRMI2PersistentManager.instance().getSession();
		return iterateRegistroByQuery(session, condition, orderBy);
	}
	
	public static java.util.Iterator iterateRegistroByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Registro as Registro");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		Query query = session.createQuery(sb.toString());
		try {
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Registro createRegistro() {
		return new orm.Registro();
	}
	
	public static boolean save(orm.Registro registro) {
		try {
			orm.AgendaRMI2PersistentManager.instance().saveObject(registro);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean delete(orm.Registro registro) {
		try {
			orm.AgendaRMI2PersistentManager.instance().deleteObject(registro);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static boolean refresh(orm.Registro registro) {
		try {
			orm.AgendaRMI2PersistentManager.instance().getSession().refresh(registro);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static Registro loadRegistroByCriteria(RegistroCriteria registroCriteria) {
		Registro[] registros = listRegistroByCriteria(registroCriteria);
		if(registros == null || registros.length == 0) {
			return null;
		}
		return registros[0];
	}
	
	public static Registro[] listRegistroByCriteria(RegistroCriteria registroCriteria) {
		return registroCriteria.listRegistro();
	}
}
